package xyz.xtt.activity.request;

import cn.hutool.core.util.IdUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import xyz.xtt.activity.entity.TblFragment;
import xyz.xtt.activity.entity.TblFragmentRecord;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class DropRequest {
	@Schema(description = "用户uid")
	@NotNull(message = "appUid必填")
	private Long appUid;
	@Schema(description = "碎片类型")
	@Max(value = 7, message = "碎片类型可选值1-7")
	@Min(value = 1, message = "碎片类型可选值1-7")
	private Integer fragmentType;
	@Schema(description = "动作类型")
	@Max(value = 8, message = "碎片类型可选值1-8")
	@Min(value = 1, message = "碎片类型可选值1-8")
	private Integer fromOperate;
	@Schema(description = "落掉时间")
	@NotNull(message = "落掉时间必填")
	private Long dropTs;

	public TblFragmentRecord buildRecord(String platform, TblFragment fragment) {
		return TblFragmentRecord
				.builder()
				.id(IdUtil.getSnowflakeNextId())
				.fragmentId(fragment.getFragmentId())
				.formUser(0L)
				.toUser(appUid)
				.fromType(0)
				.createTime(System.currentTimeMillis())
				.status(0)
				.fromOperate(fromOperate)
				.platform(platform)
				.build();
	}
}
